import * as tf from "@tensorflow/tfjs";
export const file2img = async (file) => {
    return new Promise(resolve => {
        const render = new FileReader();
        render.readAsDataURL(file);
        render.onload = (e) => {
            const img = document.createElement("img");
            img.src = e.target.result;
            img.width = 224;
            img.height = 224;
            img.onload = (i) => {
                resolve(img)
            }
        }
    })

}

export function img2x(img){
    return tf.tidy(()=>{
        return tf.browser.fromPixels(img).toFloat().sub(255/2).div(255/2).reshape([1,224,224,3])
    })
}